package fun.xinnix.consumer;

import cn.hutool.core.thread.ThreadUtil;
import com.alibaba.fastjson2.JSON;
import com.rabbitmq.client.AMQP;
import fun.xinnix.entity.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Consumer {
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "fanout.queue1", durable = "true"),
                    exchange = @Exchange(name = "fanout.ex", type = ExchangeTypes.FANOUT)
            )
    })
    public void listenerFanout1(String msg) {
        log.info("接收到消息fanout.queue1: {}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "fanout.queue2"),
                    exchange = @Exchange(name = "fanout.ex", type = ExchangeTypes.FANOUT)
            )
    })
    public void listenerFanout2(String msg) {
        log.info("接收到消息fanout.queue2: {}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "direct.queue2"),
                    exchange = @Exchange(name = "direct.ex", type = ExchangeTypes.DIRECT),
                    key = {"blue", "red"}
            )
    })
    public void listenerDirectQueue(String msg) {
        log.info("接收到消息direct.queue2: {}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "topic.queue2"),
                    exchange = @Exchange(name = "topic.ex", type = ExchangeTypes.TOPIC),
                    key = "order.#"
            )
    })
    public void listenerTopicQueue(String msg) {
        log.info("接收到消息topic.queue2: {}", msg);
    }

//    @RabbitListener(queues = {"dlx.queue"})
//    public void listenerSimpleQueue1(JsonResult msg) {
//        log.info("接收到消息dlx.queue: {}, {}", msg, JSON.toJSONString(msg));
//    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue", durable = "true"),
            exchange = @Exchange(value = "delay.direct", delayed = "true"),
            key = "haha"
    ))
    public void listenerDelayQueue(JsonResult msg) {
        log.info("接收到消息delay.queue: {}, {}", msg, JSON.toJSONString(msg));
    }
//
//    @RabbitListener(queues = {"fanout.queue2"})
//    public void listenerSimpleQueue2(String msg) {
//        log.info("接收到消息fanout.queue2: {}", msg);
//    }
//
//    @RabbitListener(queues = {"direct.queue.order"})
//    public void listenerSimpleQueueOrder(String msg) {
//        log.info("接收到消息1: {}", msg);
//    }
//
//    @RabbitListener(queues = {"direct.queue.user"})
//    public void listenerSimpleQueueUser(String msg) {
//        log.info("接收到消息2: {}", msg);
//    }
//
//    @RabbitListener(queues = {"topic.queue1"})
//    public void listenerTopicQueue1(String msg) {
//        log.info("接收到消息topic.queue1: {}", msg);
//    }
//
//    @RabbitListener(queues = {"topic.queue2"})
//    public void listenerTopicQueue2(String msg) {
//        log.info("接收到消息topic.queue2: {}", msg);
//    }
}
